<?php 
/* P3(c)

******************************************************************************
                                                                                      
                         __                                                        
                        /__)                                                       
                       /__        P3 - moving Technologie            
                        __)                                                          
                        __)                                                          
                                                                                        
                                                                                        
       Copyright 2009 by p3.co.at                                                                                 
                                                                                        
       visit www.p3.co.at to get more Informations 
       about Teriko - Betriebsdatenerfassung                                                                                 
       - it's not allowed to change this scripts
       - it's not allowed to remove this copyright-tag

       -- you can download the complete license   
          under http://www.teriko.org

 (c) by Patrik Pfaffenbauer and P3 (http://www.p3.co.at)

 | Programname: P3.Teriko
 | Authtor: P3.Verein
 | Coder: Patrik Pfaffenbauer
 | Version: 0.1

 | Change Index
 |_____________________________________________
 |                                             |
 |4.3.2010 Erstellung | Patrik Pfaffenbauer    |
 |_____________________________________________|

******************************************************************************

P3(c) */


class Menue
{
	public function Menue()
	{
		session_start();
		$site = $_GET['s'];
		
		if($_SESSION['loggedIn'] == "")
			$site = "login";
			
		if($site == login)
			return;
		
		include("./_tables.php");
		
		$query = "SELECT *,DATE_FORMAT(startTime,'%d.%m.%Y %H:%i') as start FROM ".$tbljobtimes." WHERE userID = ".$_SESSION['userid']." AND endTime IS NULL";
		$res = $GLOBALS['db']->Query($query);
		
		$query = "SELECT *,DATE_FORMAT(startTime,'%d.%m.%Y %H:%i') as start FROM ".$tblpausetimes." WHERE userID = ".$_SESSION['userid']." AND endTime IS NULL";
		$res2 = $GLOBALS['db']->Query($query);
		
		if($GLOBALS['db']->NumRow($res))
		{
			$res = $GLOBALS['db']->Fetch($res);
			$query = "SELECT * FROM ".$tbljobs." WHERE id=".$res->jobID;

			$res2 = $GLOBALS['db']->Fetch($GLOBALS['db']->Query($query));
			$job = $res2->name;
			$startTime = $res->start;
			$jobID = $res->jobID;
			$jobComment = str_replace("<br />", "\n",$res->comment);
			$text = $startTime." - ".$job;
			$runningJob = true;
		}
		else if($GLOBALS['db']->NumRow($res2))
		{
			$res = $GLOBALS['db']->Fetch($res2);
			$query = "SELECT * FROM ".$tblpause." WHERE id=".$res->pauseid;

			$res2 = $GLOBALS['db']->Fetch($GLOBALS['db']->Query($query));
			$job = $res2->pauseName;
			$startTime = $res->start;
			$text = $startTime." - ".$job;
			$runningPause = true;
		}
		else
		{
			$job = $GLOBALS['lang']->GetLanguage("Online", "noRunningJob");
			$startTime = "";
			$text = $job;
			$runningJob = false;
		}
		
		echo '	<div id="module-menu">
						<ul id="menu" >
						<li class="node" id="nodeSite" style="z-index:100;"><a id="anodeSite">'.$GLOBALS['lang']->GetLanguage("Menue","home").'</a>
							<ul>
								<li><a class="icon-16-cpanel" href="index.php">'.$GLOBALS['lang']->GetLanguage("Menue","controllCenter").'</a></li>
								
								<li class="separator"><span></span></li>
								<li><a class="modal" href="iframe.php?s=member&action=paintcp&type=iframe" class="modal" rel="{handler:\'iframe\',size:{x:840,y:550}}">'.$GLOBALS['lang']->GetLanguage("Member","changePassword").'</a></li>
								<li><a class="icon-16-config" href="index.php?s=configuration">'.$GLOBALS['lang']->GetLanguage("Configuration","title").'</a></li>
								<li class="separator"><span></span></li>
								<li><a class="icon-16-logout" href="index.php?s=login&action=logout">'.$GLOBALS['lang']->GetLanguage("Login","logoff").'</a></li>
							</ul>
						</li>';
		
		$member = new Member();
		$customer = new Customer();
		$permission = new Permission();
		$country = new Country();
		$lang = new Language();
		$pause = new Pause();
		$holiday = new Holiday();
		$homenews = new Homenews();
		$department = new Department();
		
						
		if($department->allowed || $member->allowed || $customer->allowed || $permission->allowed || $country->allowed || $lang->allowed || $pause->allowed || $holiday->allowed || $homenews->allowed)
		{
			echo'<li class="node" id="nodeBase" style="z-index:99;"><a id="anodeBase">'.$GLOBALS['lang']->GetLanguage("Menue", "baseData").'</a>
				<ul>';
			
			if($department->allowed)
				echo '<li><a class="icon-16-user" href="index.php?s=department">'.$GLOBALS['lang']->GetLanguage("Department", "title").'</a></li>';
			if($member->allowed)
				echo '<li><a class="icon-16-user" href="index.php?s=member">'.$GLOBALS['lang']->GetLanguage("Member", "title").'</a></li>';
			if($customer->allowed)
				echo '<li><a class="icon-16-customer" href="index.php?s=customer">'.$GLOBALS['lang']->GetLanguage("Customer", "title").'</a></li>';
			if($permission->allowed)
				echo '<li><a class="icon-16-permission" href="index.php?s=permission">'.$GLOBALS['lang']->GetLanguage("Permission", "title").'</a></li>';
				
			if($country->allowed || $lang->allowed || $pause->allowed)
			{
				echo '<li class="separator"><span></span></li>';
				
				if($country->allowed)
					echo '<li><a class="icon-16-language" href="index.php?s=country">'.$GLOBALS['lang']->GetLanguage("Country", "title").'</a></li>';
				if($lang->allowed)
					echo '<li><a class="icon-16-language" href="index.php?s=language">'.$GLOBALS['lang']->GetLanguage("Language", "title").'</a></li>';
				if($pause->allowed)
					echo '<li><a class="icon-16-pause" href="index.php?s=pause">'.$GLOBALS['lang']->GetLanguage("Pause", "title").'</a></li>';
			}
			if($holiday->allowed)
			{
				echo '<li class="separator"><span></span></li>
					<li><a class="icon-16-media" href="index.php?s=holiday">'.$GLOBALS['lang']->GetLanguage("Holiday", "title").'</a></li>';
			}
			if($homenews->allowed)
			{
				echo '<li class="separator"><span></span></li>
					<li><a class="icon-16-static" href="index.php?s=homenews">'.$GLOBALS['lang']->GetLanguage("Homenews", "title").'</a></li>';
			}
			
			
			echo'		</ul>
						</li>';
		}		
		
		$project = new Project();
		$task = new Task();
		
		if($project->allowed || $task->allowed)
		{
			echo'<li class="node" id="nodeProjekt" style="z-index:98;"><a id="anodeProjekt">'.$GLOBALS['lang']->GetLanguage("Menue","projects").'</a>
					<ul>';
			
			if($project->allowed)
				echo '<li><a class="icon-16-project" href="index.php?s=project">'.$GLOBALS['lang']->GetLanguage("Project", "title").'</a></li>';
			if($task->allowed)
				echo '<li><a class="icon-16-article" href="index.php?s=task">'.$GLOBALS['lang']->GetLanguage("Task", "title").'</a></li>';

			echo'</ul></li>';
		}
		
		$online = new Online();
		
		if($online->allowed)
		{
		
			echo '<li class="node" id="nodeOnline" style="z-index:97;"><a id="anodeOnline">'.$GLOBALS['lang']->GetLanguage("Menue", "online").'</a>
				 <ul>';
		
			if($runningJob)
			{
				echo '<li><a class="icon-16-online" href="index.php?s=online&jobid='.$jobID.'">'.$GLOBALS['lang']->GetLanguage("Menue", "timeRecord").'</a></li>';
			}
			else
			{
				echo '<li><a class="icon-16-online" href="index.php?s=online">'.$GLOBALS['lang']->GetLanguage("Menue", "timeRecord").'</a></li>';
			}
						
			echo '</ul>
				</li>';
		}
		
		$offline = new Offline();
		
		if($offline->allowed)
		{
			echo '
			<li class="node" id="nodeOffline" style="z-index:96;"><a id="anodeOffline">'.$GLOBALS['lang']->GetLanguage("Menue", "offline").'</a>
				<ul>
					<li><a class="icon-16-offline" href="index.php?s=offline">'.$GLOBALS['lang']->GetLanguage("Menue", "timeRecord").'</a></li>
				</ul>
			</li>';
		}
		
		$report = new ReportSystem();
		if($report->allowed)
		{
			echo '
			<li class="node" id="nodeReport" style="z-index:95;"><a id="anodeReport">'.$GLOBALS['lang']->GetLanguage("Menue", "reportSystem").'</a>
				<ul>
					<li><a class="icon-16-offline" href="index.php?s=reportsystem">'.$GLOBALS['lang']->GetLanguage("Reportsystem", "title").'</a></li>
				</ul>
			</li>';
		}

		$system = new System();
		$help = new Help();
		
		if($help->allowed || $system->allowed)
		{
			echo'
			<li class="node" id="nodeHelp" style="z-index:94;"><a id="anodeHelp">'.$GLOBALS['lang']->GetLanguage("Help", "title").'</a>
				<ul>';
			
			if($help->allowed)
				echo '<li><a class="icon-16-help" href="index.php?s=help">'.$GLOBALS['lang']->GetLanguage("Help", "teriko-help").'</a></li>';
			if($system->allowed)
				echo '<li><a class="icon-16-info" href="index.php?s=system">'.$GLOBALS['lang']->GetLanguage("System", "title2").'</a></li>';
			
			echo '</ul>
			</li>';
		}
						
		echo '<li class="node" ><div style="color:transparent;">plac</div></li>';
		
		if($runningJob)
		{
			echo '<li class="node" id="nodeRunningJob" style="z-index:93;"><a id="anodeRunningJob" href="index.php?s=online&jobid='.$jobID.'">'.$GLOBALS['lang']->GetLanguage("Online","runningJob").': '.$text.'</a></li>';
			//echo '<li class="node" id="nodeAddMember" style="z-index:93;"><a id="anodeAddMember" href="javascript:void(0)" onClick=""><img src="images/add.png" alt="add" />'.$GLOBALS['lang']->GetLanguage("Online", "addMember").'</a></li>';
			echo '
			<li class="node" id="nodePause"><a id="anodePause"><img src="images/pause.png" alt="stop" />'.$GLOBALS['lang']->GetLanguage("Online", "pauseJob").'</a>
				<ul>';
			$query = "SELECT * FROM ".$tblpause;
			$res = $GLOBALS['db']->Query($query);
			
			while($line = $GLOBALS['db']->Fetch($res))
			{
				echo '<li><a class="icon-16-pause" href="javascript:void(0)" onClick="PauseRunningJob(\''.$jobID.'\',\''.$line->id.'\')">'.$line->pauseName.'</a></li>';
			}
					//
			echo '
					<div id="pauseDiv"></div>
				</ul>
			</li>
			';
			
			echo '
			<li class="node" id="nodeStopJob" style="z-index:92;"><a id="anodeStopJob" href="javascript:void(0)"><img src="images/stop.png" alt="stop" />'.$GLOBALS['lang']->GetLanguage("Online", "stopJob").'</a>
				<ul>
					<li>
					
						<table name="stopCommentTable" id="stopCommentTable">
							<tr>
								<td>
									<a class="icon-16-comment"><textarea id="stopCommentText" name="stopCommentText" cols="20" rows="10">'.$jobComment.'</textarea></a>
								</td>
							</tr>
						</table>
					</li>
					<li>
						<table>
							<tr>
								<td width="200px" align="center">
									<a class="icon-16-comment" href="javascript:void(0)" onClick="StopRunningJob(\''.$jobID.'\')">'.$GLOBALS['lang']->GetLanguage("Online", "stopJob").'</a>
								</td>
							</tr>
						</table>						
					</li>
				</ul>
			</li>
			
			';
			echo '<li class="node" id="nodeComment" style="z-index:91;"><a id="anodeComment" href="javascript:void(0)"><img src="images/comment.png" alt="comment" />'.$GLOBALS['lang']->GetLanguage("Online", "commentJob").'</a>
						<ul>
			<li>
				<table name="commentTable" id="commentTable">
					<tr>
						<td>
							<a class="icon-16-comment"><textarea id="commentText" name="commentText" cols="20" rows="10">'.$jobComment.'</textarea></a>
						</td>
					</tr>
				</table>				
			</li>
			<li>
				<table>
					<tr>
						<td width="200px" align="center">
							<a class="icon-16-comment" href="javascript:void(0)" onClick="CommentRunningJob(\''.$jobID.'\', \'commentText\', \'commentTextActualJob\', \'commentResult\')" >'.$GLOBALS['lang']->GetLanguage("Common", "save").'</a>
						</td>
					</tr>
					<tr>
						<td>
							<div id="commentResult"></div>
						</td>
					</tr>
				</table>
			</li>
			</ul></li>';
			
		}
		else if($runningPause)
		{
			
			echo '<li class="node" id="nodeRunningJob" style="z-index:94;"><a id="anodeRunningJob" href="index.php?s=online">'.$GLOBALS['lang']->GetLanguage("Online","runningJob").': '.$text.'</a></li>';	
			
			$jobtime = $GLOBALS['db']->Fetch($GLOBALS['db']->Query("SELECT *,DATE_FORMAT(startTime,'%d.%m.%Y %H:%i') as start FROM ".$tbljobtimes." WHERE userID = ".$_SESSION['userid']." order by endTime desc limit 0,1"));
			$job = $GLOBALS['db']->Fetch($GLOBALS['db']->Query("SELECT * FROM ".$tbljobs." WHERE id=".$jobtime->jobID));
			$project = $GLOBALS['db']->Fetch($GLOBALS['db']->Query("SELECT * FROM ".$tblproject." WHERE id=".$job->projectID));
			$customer = $GLOBALS['db']->Fetch($GLOBALS['db']->Query("SELECT * FROM ".$tblcustomer." WHERE id=".$project->customerID));
			
			$lastJob = '<strong>'.$customer->name."</strong><br/>".$project->name." - ".$job->name;
			
			echo '
			<li class="node" id="nodeStartLastJob" style="z-index:95;"><a id="anodeStartLastJob" href="javascript:void(0)">'.$GLOBALS['lang']->GetLanguage("Online", "startLastJob").'</a>
				<ul>
					<li>
						<a>'.$lastJob.'</a>
					</li>
					<li>
						<table name="commentLastJob" id="commentLastJob">
							<tr>
								<td>
									<a class="icon-16-comment"><textarea id="commentLastJobText" name="commentLastJobText" cols="20" rows="10"></textarea></a>
								</td>
							</tr>
						</table>				
					</li>
					<li>
						<table>
							<tr>
								<td width="200px" align="center">
									<a href="javascript:void(0)" onClick="StartLastJob()" >'.$GLOBALS['lang']->GetLanguage("Online", "runJob").'</a>
								</td>
							</tr>
							<tr>
								<td>
									<div id="commentResult"></div>
								</td>
							</tr>
						</table>
					</li>
					<li>
					<div id="lastJobResult"></div>
				</ul>
			</li>';
		}
		else
		{
			echo '<li class="node" id="nodeRunningJob" style="z-index:94;"><a id="anodeRunningJob" href="index.php?s=online">'.$GLOBALS['lang']->GetLanguage("Online","runningJob").': '.$text.'</a></li>';		
		}
		echo '</ul>
		</div>
		<div class="clr"></div>';
	}
}

?>